var e = require;
var t = module;
cc.Class({
    extends: cc.Component,
    properties: {
        scrollView: cc.ScrollView,
        content: cc.Layout,
        selectedBg: cc.Node,
        pbLListViewItem: cc.Prefab,
        placeHolder: cc.Node
    },
    start: function start() {
        var e = cc.instantiate(this.pbLListViewItem),
            t = this.content.spacingY,
            c = e.height,
            i = this.content.node._children.length,
            o = this.content.node.convertToWorldSpaceAR(cc.Vec2.ZERO),
            n = this.scrollView.node.convertToWorldSpaceAR(cc.Vec2.ZERO),
            l = o.y - n.y;
        if (
            ((this.placeHolder.height = l - c / 2 - t),
            (this.content.node.height =
                (t + c) * i + this.scrollView.node.height / 2 - c / 2 + this.placeHolder.height - (t + c)),
            (this.curSelectedIndex = 0),
            this.selectCB)
        ) {
            var s = this.content.node._children;
            this.selectCB(this.curSelectedIndex, s[this.curSelectedIndex + 1]);
        }
    },
    setItems: function setItems(e) {
        for (var t = 0; t < e.length; t++) {
            var c = cc.instantiate(this.pbLListViewItem);
            (c.getComponent(cc.Label).string = e[t]), (c.parent = this.content.node);
        }
    },
    setSelectCB: function setSelectCB(e) {
        this.selectCB = e;
    },
    scrollEvent: function scrollEvent(e, t) {
        t == cc.ScrollView.EventType.SCROLL_ENDED ? this.calScrollY() : this.calScale();
    },
    calScrollY: function calScrollY() {
        var e = this.content.node._children,
            t = this.selectedBg.convertToWorldSpaceAR(cc.Vec2.ZERO),
            c = 999999,
            i = 0,
            o = 0,
            n = 0;
        for (n = 0; n < e.length; n++) {
            var l = e[n].convertToWorldSpaceAR(cc.Vec2.ZERO).y - t.y,
                s = Math.abs(l);
            s < c && ((c = s), (i = n), (o = -l));
        }
        if (0 != o) {
            var r = this.scrollView.getScrollOffset(),
                d = cc.v2(r.x, r.y + o);
            this.scrollView.scrollToOffset(d, 0.1);
        }
        this.curSelectedIndex != i - 1 &&
            ((this.curSelectedIndex = i - 1),
            this.selectCB && this.selectCB(this.curSelectedIndex, e[this.curSelectedIndex + 1]));
    },
    calScale: function calScale() {
        var e = this.content.node._children,
            t = this.selectedBg.convertToWorldSpaceAR(cc.Vec2.ZERO),
            c = 999999,
            i = 0,
            o = 0,
            n = 0;
        for (n = 0; n < e.length; n++) {
            var l = e[n].convertToWorldSpaceAR(cc.Vec2.ZERO).y - t.y,
                s = Math.abs(l);
            s < c && ((c = s), (i = n), (o = -l));
        }
        if (0 != o) {
            var r = 1,
                d = 0;
            for (n = i; n < e.length; n++) {
                (r = 1 - 0.1 * d) < 0.1 && (r = 0.1), (e[n].scale = r), d++;
            }
            for (d = 0, n = i; n > -1; n--) {
                (r = 1 - 0.1 * d) < 0.1 && (r = 0.1), (e[n].scale = r), d++;
            }
        }
    }
});
